package com.xuecheng.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

/**
 * MyBatis-Plus 代码生成类
 */
public class ContentCodeGenerator {

	// TODO 修改服务名以及数据表名
	private static final String SERVICE_NAME = "content";

	//数据库账号
	private static final String DATA_SOURCE_USER_NAME  = "root";
	//数据库密码
	private static final String DATA_SOURCE_PASSWORD  = "mysql";
	//生成的表
	private static final String[] TABLE_NAMES = new String[]{
//			"mq_message",
//			"mq_message_history"
//			 "course_base",
//			 "course_market",
//			 "teachplan",
//			 "teachplan_media",
//			 "course_teacher",
//			"course_category"
			 "course_publish",
			 "course_publish_pre"
	};

//	public static final String Path = "C:/java_lesson/demo/xuecheng-plus/xuecheng-plus-parent/xuecheng-plus-generator";

	public static void main(String[] args) {
		FastAutoGenerator.create("jdbc:mysql://localhost:3306/xc_content", "root", "root")
				.globalConfig(builder -> builder
						.author("yellow Doctor")
//						.outputDir(Path + "/src/main/java")
						.outputDir(Paths.get(System.getProperty("user.dir"))+
								"/xuecheng-plus/xuecheng-plus-parent/xuecheng-plus-generator" + "/src/main/java")
						.commentDate("yyyy-MM-dd")
				)
				.packageConfig(builder -> builder
						.parent("com.xuecheng.content")
						.entity("entity")
						.mapper("mapper")
						.service("service")
						.serviceImpl("service.impl")
						.xml("mapper.xml")
				)
				.strategyConfig(builder -> builder
//						.addInclude("course_publish","course_publish_pre")
						.addFieldPrefix("course_")
						.entityBuilder()
						.enableLombok()
				)
				// ✅ 关键：注入自定义变量，解决 swagger2 未定义问题
				.injectionConfig(builder -> {
					Map<String, Object> customMap = new HashMap<>();
					// ✅ 明确设置 swagger2 为 true 或 false
//					customMap.put("swagger2", true); // 如果您想使用 Swagger 注解
					 customMap.put("swagger2", false); // 如果不想使用
					builder.customMap(customMap);
				})
				.templateEngine(new FreemarkerTemplateEngine())
				.execute();
		System.out.println(" 代码生成结束... ");
	}
}
